<?php

class Editor extends CI_Controller {
    public $data = array();

    public function __construct() {

        parent::__construct();
        // parent::__construct(); for CI 2.x users

        //$this->load->helper('url'); //You should autoload this one ;)
        $this->load->helper('ckeditor');
        $this->load->library('form_validation');
        $this->load->model('Ckeditor_model');

        //Ckeditor's configuration
        $this->data['ckeditor'] = array(
            //ID of the textarea that will be replaced
            'id' => 'mieditor', //NOmbre del textarea del formulario
            'path' => 'js/ckeditor',
            //Optionnal values
            'config' => array(
                'toolbar' => "Personalizado", //Using the Full toolbar
                'width' => "700px", //Setting a custom width
                'height' => '100px' //Setting a custom height
                
            ),
            //Replacing styles from the "Styles tool"
            'styles' => array(
                //Creating a new style named "style 1"
                'style 1' => array(
                    'name' => 'Blue Title',
                    'element' => 'h2',
                    'styles' => array(
                        'color' => 'Blue',
                        'font-weight' => 'bold'
                    )
                ),
                //Creating a new style named "style 2"
                'style 2' => array(
                    'name' => 'Red Title',
                    'element' => 'h2',
                    'styles' => array(
                        'color' => 'Red',
                        'font-weight' => 'bold',
                        'text-decoration' => 'underline'
                    )
                )
            )
        );
    }

    public function index() {
        $this->load->view('myform', $this->data);
    }
    
    function guardar() {
        $this->form_validation->set_rules('mieditor', 'Nombre', 'trim');
        if ($this->form_validation->run() == FALSE) {
            $this->index();
        } else {
            //captura los datos via post
            $descripcion = $this->input->post('mieditor');
            //$descripcion = $this->textarea->post('mieditor');
            $this->Ckeditor_model->guardar($descripcion);
            echo 'Se registro correctamente';
            echo anchor('editor', 'Regresar');
        }
    }

}